﻿using System;
using System.Collections.Generic;
using COM.Service;
using SampleApp.Domain;


namespace SampleApp.Service
{
    public interface IDataCacheService : ICacheServiceBase
    {
        List<SysUser> UserList { get; }
        List<SysDept> DeptList { get; }
    }

    public class DataCacheService : IDataCacheService
    {
        private IUnity unity;
        public DataCacheService(IUnity unity)
        {
            this.unity = unity;
        }


        private List<SysUser> userList;
        public List<SysUser> UserList
        {
            get
            {
                if (this.userList == null)
                {
                    this.userList = this.unity.GetService<ISysUserService>().GetSysUserListFromDatabase();
                }
                return userList;
            }
        }


        private List<SysDept> deptList;
        public List<SysDept> DeptList
        {
            get
            {
                if (this.deptList == null)
                {
                    this.deptList = this.unity.GetService<ISysDeptService>().GetDeptListFromDatabase();
                }
                return deptList;
            }
        }

        public void Reload()
        {
            this.userList = null;
            this.deptList = null;
            if (this.EventReload != null)
                this.EventReload(this, EventArgs.Empty);
        }

        public event EventHandler EventReload;

    }

}
